// $(document).ready(function () {
//     App.init();
//     TableManageFixedHeader.init();
// });

//分页展示
var channeltable;
$(document).ready(function () {
    channeltable = $("#channeltable").DataTable({
        "bAutoWidth": false,
        "order": [],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [15],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "ajax": {
            "url": "/receivable/queryChannelTableData",
            "dataSrc": "aaData",
            "data": function (params) {
                params.insurer = $('#channelInsurer').val(); //保险公司
                params.orderNum = $('#channelOrderNumber').val(); //保单号
                params.plateNumber = $('#channelPlateNumber').val(); //车牌号
                params.channelIds = $('#orderChannelId').val(); //渠道ID
                params.accountMaturityDateStart = $('#accountMaturityDateStart').val(); //渠道账期到期日开始
                params.accountMaturityDateEnd = $('#accountMaturityDateEnd').val(); //渠道账期到期日结束
                var status = $('#channelStatus').val(); //状态
                if(status != 0){
                    params.status = status ;
                }else{
                    params.status = "3,4,7,8";
                }
            },
            "error": function (xhr, ts, et) {
                if (ts == "parsererror") {
                    window.location.href = '/logout';
                    return;
                }
            }
        },
        "columns": [
            {"data": null,
                "render": function (data, type, row) {
                    return "<a href='javascript:void(0);' onclick='orderInfoDetail(" + row.ordId + ")' class='btn-link'>" + row.orderNum + "</a>";
                }, "bSortable": false},
            { "data": "paySubject" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>环宇康泰</span>";else if(data==2)return "<span>青岛盛达</span>";else if(data==3)return "<span>玉环天云</span>";else if(data==4)return "<span>汉龙</span>";
                    return data;
            },"bSortable": false},
            {"data": "insurer", "bSortable": false},
            {"data": "member.name", "bSortable": false},
            {"data": "member.telephone" ,"bSortable": false},
            { "data": "insuranceType" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>交强险</span>";else if(data==1)return "<span>商业险</span>";
                    return data;
            },"bSortable": false},
            {"data": "insurant", "bSortable": false},
            {"data": "insurantIdcard", "bSortable": false},
            {"data": "plateNumber", "bSortable": false},
            {"data": "mercialPremium",
                "render": function (data, type, row) {
                    if(data!=null)return "<div class='text-right'>" + row.mercialPremium + "</div>";else return "<div></div>";
            },"bSortable": false},
            {"data": "pulsoryPremium",
                "render": function (data, type, row) {
                    if(data!=null)return "<div class='text-right'>" + row.pulsoryPremium + "</div>";else return "<div></div>";
            },"bSortable": false},
            {"data": "vehicleVesselTax",
                "render": function (data, type, row) {
                    if(data!=null)return "<div class='text-right'>" + row.vehicleVesselTax + "</div>";else return "<div></div>";
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.allPremium + "</div>";
            },"bSortable": false},
            {"data": "orderDate", "bSortable": false},
            {"data": "insuranceDate", "bSortable": false},
            {"data": "channelPoint", "bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.channelRebate + "</div>";
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.mustPremium + "</div>";
            },"bSortable": false},
            {"data": "accountMaturityDate", "bSortable": false},
            { "data": "status" ,
                "render": function (data, type, full, meta) {
                    if(data==3)return "<span>待结算</span>";else if(data==4)return "<span>待审核</span>";else if(data==7)return "<span>结算审核驳回</span>";else if(data==8)return "<span>已逾期</span>";
                    return data;
            },"bSortable": false}
        ],
        "columnDefs": [{
            "targets": 20,//是操作按钮目标列
            "data": null,
            "render": function (data, type, row) {
                var html = ""
                if (row.status == 3 || row.status == 7 || row.status == 8) {
                    html += "<shiro:hasPermission name='应收渠道列表-结算'><a href='javascript:void(0);' onclick='orderSettlementModal(" + row.tid + ", " + row.member.channelId + ")' class='btn-link'>结算</a></shiro:hasPermission>";
                } else if (row.status == 4) {
                    html += "<shiro:hasPermission name='应收保险公司列表-结算审核'><a href='javascript:void(0);' onclick='settlementAudit(" + row.ordId + ", 2)' class='btn-link'>结算审核</a></shiro:hasPermission>";
                }
                return html;
            }
        }]
    });
});

function channelOrderSearch(){
    channeltable.ajax.reload();
}